package jalgebrava.group.groups;

import static jalgebrava.util.collections.IterableMixins.*;
import jalgebrava.group.Group;
import jalgebrava.group.GroupElement;
import jalgebrava.util.collections.ImmutableIterable;
import jalgebrava.util.collections.ImmutableIterator;
/**
 * Provides sensible default implementations.
 * @param <G> type of group element.
 */
public abstract class AbstractGroup<G> extends Group<G> {
	
	private final int size;
	private final ImmutableIterable<G> baseIterable;
	
	protected AbstractGroup(String inDescription, ImmutableIterable<G> inIterable, int size) {
		super(inDescription);
		this.baseIterable = inIterable;
		this.size = size;
		

	}

	@Override
	public boolean equals(G x, G y) {		
		return x.equals(y);
	}

	@Override
	public int hashCode(G x) {
		return x.hashCode();
	}

	@Override
	public String toShortString(G x) {
		return x.toString();
	}
	@Override
	public String toString(G x) {
		
		return toShortString(x)+"("+this.toString()+")";
	}	
	
	@Override
	public final String toString() {
		return this.getDescription();
	}
	
	@Override
	public ImmutableIterator<G> iterator() {
		return baseIterable.iterator();
	}
	@Override
	public ImmutableIterable<GroupElement<G>> elements() {		
		return map(baseIterable, element);		
	}
	
	@Override
	public int size() {
		return size;
	}

	
	
}
